package com.telecom.weixi.view;

import com.telecom.weixi.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ItemMenuView extends RelativeLayout {
	String mStrTitle;
	Drawable mImgIcon;
	Drawable mImgArrow;
	String mStrSubTitle;
	
	public ItemMenuView(Context context){
		this(context, null);
	}
	
	public ItemMenuView(Context context, AttributeSet attrs){
		this(context, attrs, 0);
	}
	
	public ItemMenuView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		if(attrs != null){
			TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MenuItem);
			mStrTitle = a.getString(R.styleable.MenuItem_itemText);
			mImgIcon = a.getDrawable(R.styleable.MenuItem_preIcon);
			mImgArrow = a.getDrawable(R.styleable.MenuItem_arrowIcon);
			mStrSubTitle = a.getString(R.styleable.MenuItem_subText);
		}
		
		setupView(context);
	}
	
	void setupView(Context context){
		LayoutInflater flater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		flater.inflate(R.layout.item_menu_search, this);
		
		ImageView logo = (ImageView) findViewById(R.id.menu_item_logo);
		TextView title = (TextView) findViewById(R.id.menu_item_title);
		ImageView arrow = (ImageView) findViewById(R.id.menu_item_arrow);
		TextView subTitle = (TextView) findViewById(R.id.sub_title);
		
		title.setText(mStrTitle);
		subTitle.setText(mStrSubTitle);
		if(mImgIcon != null){
			logo.setImageDrawable(mImgIcon);
		}
		if(mImgArrow == null){
			mImgArrow = context.getResources().getDrawable(R.drawable.detail_arrow);
		}
		arrow.setImageDrawable(mImgArrow);
	}

}
